import { Queue } from "./04_数组实现队列结构";

const hotPotato = (nameList: string[], num: number): string => {
  if (nameList.length < 0) return `-1`;
  const queue = new Queue<string>();

  for (let i = 0; i < nameList.length; i++) {
    queue.enqueue(nameList[i]);
  }

  while (queue.size > 1) {
    //1.不是num的元素出栈入栈
    //2.是num元素出栈
    for (let s = 0; s < num - 1; s++) {
      const name = queue.dequeue();
      if (name) {
        queue.enqueue(name);
      }
    }
    queue.dequeue();
  }
  return queue.dequeue()!;
};
var names = ["John", "Jack", "Camila", "Ingrid", "Carl"];
var winner = hotPotato(names, 7);
console.log("胜利者：" + winner);
